<template>
  <div>
    {{ fileList }}
    <el-upload
      class="upload-demo"
      action="/dev-api/upla"
      :multiple="true"
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :auto-upload="true"
      :show-file-list="false"
      :on-success="onSuccess"
      accept="text/plain"
    >
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
  </div>
</template>
<script>
export default {
  data() {
    return {
      fileList: [],
    };
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    onSuccess(response, file, fileList) {
      let arr = file.name.split(".");
      let name = arr.slice(0, arr.length - 1)[0];
      console.log(name);
      this.fileList = [name];
      this.$emit("upload", false);
      console.log(response, file, fileList);
    },
  },
  destroyed() {
    this.fileList = [];
  },
};
</script>
